from rest_framework import renderers
from .constant import SUCCESS_CODE, SUCCESS_MSG


# 自定义基础json渲染器
class ResultJsonRenderer(renderers.JSONRenderer):
    def render(self, data, accepted_media_type=None, renderer_context=None):
        if renderer_context:
            new_data = {"code": SUCCESS_CODE, "msg": SUCCESS_MSG, "data": data}
            return super().render(new_data, accepted_media_type, renderer_context)
        else:
            return super().render(data, accepted_media_type, renderer_context)
